package com.liyunc.demo.controller;

import com.liyunc.demo.enums.ResultCode;
import com.liyunc.demo.pojo.UserInfo;
import com.liyunc.demo.result.CommonResult;
import com.liyunc.demo.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/v1/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    /**
     * find all users.
     */
    @GetMapping(value = "")
    public CommonResult<List<UserInfo>> findAll() {
        List<UserInfo> users = userInfoService.findAll();
        if (!users.isEmpty()) {
            return CommonResult.success(users);
        } else {
            return CommonResult.failed(ResultCode.FAILED.getCode(), "find fail");
        }
    }
}
